{extend name="index/index" /}

<!--main-->
{block name="main"}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="#">Home</a>
            </li>

            <li>
                <a href="/privilege">角色权限分配</a>
            </li>
            <li class="active">权限分配</li>
        </ul><!-- .breadcrumb -->

        <!--<div class="nav-search" id="nav-search">-->
            <!--<form class="form-search">-->
								<!--<span class="input-icon">-->
									<!--<input type="text" placeholder="Search ..." class="nav-search-input"-->
                                           <!--id="nav-search-input" autocomplete="off"/>-->
									<!--<i class="icon-search nav-search-icon"></i>-->
								<!--</span>-->
            <!--</form>-->
        <!--</div>&lt;!&ndash; #nav-search &ndash;&gt;-->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                角色
                <small>
                    >

                    权限分配（新增修改角色权限、删除权限、新增角色） <button style="margin-left:30px" type="button" class="btn btn-xs btn-danger " data-toggle="modal" data-target="#myModal1"> 新增角色 </button>

                </small>
            </h1>
        </div><!-- /.page-header -->

        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->

                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-responsive">
                            <table id="sample-table-2" class=" notab table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="center">
                                        <label>
                                            <input type="checkbox" class="ace"/>
                                            <span class="lbl"></span>
                                        </label>
                                    </th>
                                    <th>编号</th>
                                    <th>角色</th>
                                    <th class="hidden-480">可访问的控制器</th>

                                    <th>
                                        <i class=" hidden-480"></i>
                                        可访问的方法
                                    </th>
                                    <th class="hidden-480">PID(权限ID)</th>
                                    <th class="hidden-480">操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                <!--tr-->
                                
                                <tr>
                                    <td class="center">
                                        <label>
                                            <input type="checkbox" class="ace"/>
                                            <span class="lbl"></span>
                                        </label>
                                    </td>

                                    <td>
                                        <a href="#">12</a>
                                    </td>
                                    <td>root</td>
                                    <td class="hidden-480">*</td>
                                    <td> *</td>

                                    <td class="hidden-480">
                                        <span class="label label-sm label-warning">
                                       *
                                        </span>
                                    </td>

                                    <td>
                                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">


                                        </div>

                                        <div class="visible-xs visible-sm hidden-md hidden-lg">
                                            <div class="inline position-relative">
                                                <button class="btn btn-minier btn-yellow dropdown-toggle"
                                                        data-toggle="dropdown">
                                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                                </button>

                                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
                                                    <li>
                                                        <a href="#" class="tooltip-info" data-rel="tooltip"
                                                           title="View">
                                                                                <span class="blue">
                                                                                    <i class="icon-zoom-in bigger-120"></i>
                                                                                </span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a href="#" class="tooltip-success" data-rel="tooltip"
                                                           title="Edit">
                                                                                <span class="green">
                                                                                    <i class="icon-edit bigger-120"></i>
                                                                                </span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a   class="tooltip-error " data-rel="tooltip"
                                                             title="Delete" >
                                                                                <span class="red">
                                                                                    <i class="icon-trash bigger-120"></i>
                                                                                </span>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                        {volist name="list" id="v"}
                                <tr>
                                    <td class="center">
                                        <label>
                                            <input type="checkbox" class="ace"/>
                                            <span class="lbl"></span>
                                        </label>
                                    </td>

                                    <td>
                                        <a href="#">{$v['rid']}</a>
                                    </td>
                                    <td>{$v['rname']}</td>
                                    <td class="hidden-480">{$v['controller']}</td>
                                    <td> {$v['method']}</td>

                                    <td class="hidden-480">
                                        <span class="label label-sm label-warning">
                                       {$v['pid']}
                                        </span>
                                    </td>

                                    <td>
                                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">


                                            <a class="green add-btn"  data-toggle="modal" data-name="{$v['rname']}" data-id="{$v['rid']}"  data-target="#myModal">
                                                <i class="icon-pencil bigger-130"></i>
                                            </a>

                                            <a class="red del-btn " data-oid="{$v['rid']}" data-pid="{$v['pid']}"  >
                                                <i class="icon-trash bigger-130"></i>
                                            </a>


                                        </div>

                                        <div class="visible-xs visible-sm hidden-md hidden-lg">
                                            <div class="inline position-relative">
                                                <button class="btn btn-minier btn-yellow dropdown-toggle"
                                                        data-toggle="dropdown">
                                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                                </button>

                                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
                                                    <li>
                                                        <a href="#" class="tooltip-info" data-rel="tooltip"
                                                           title="View">
																				<span class="blue">
																					<i class="icon-zoom-in bigger-120"></i>
																				</span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a href="#" class="tooltip-success" data-rel="tooltip"
                                                           title="Edit">
																				<span class="green">
																					<i class="icon-edit bigger-120"></i>
																				</span>
                                                        </a>
                                                    </li>

                                                    <li>
                                                        <a   class="tooltip-error " data-rel="tooltip"
                                                             title="Delete" >
																				<span class="red">
																					<i class="icon-trash bigger-120"></i>
																				</span>
                                                        </a>
                                                    </li>
                                                </ul>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <!--endtr-->
                                {/volist}
                                </tbody>
                            </table>

                        </div>
                    </div>
                </div>





                <!-- Modal -->
                <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">新增角色</h4>
                            </div>
                            <form action="{:url('admin/privilege/addrole')}" method="post">
                            <div class="modal-body">
                                    <input type="text" name="name" id='ipp'>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <button type="submit" class="btn btn-primary">Save changes</button>
                            </form>
                            </div>
                        </div>
                    </div>
                </div>





                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">新增权限</h4>
                            </div>
                            <div class="modal-body">

                                <form action="{:url('admin/privilege/save')}" method="post">
                                    <font id="rid" class="btn-info" size="4"></font>
                                    <font id="rname" class="btn-danger" size="4"></font>
                                  <input id="bianhao" type="hidden" name="rid" value="">
                                  <input id="juese" type="hidden" name="role" value="">
                                    <select name="addrole[]" multiple class="form-control">
                                        {volist name="data" id="v"}
                                        <option  value="{$v['id']}">{$v['controller']}--{$v['method']}</option>
                                        {/volist}
                                    </select>
                            </div>
                            <div class="modal-footer">
                                <button type="submit" class="btn btn-primary">Save changes</button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>





{/block}
<!-- basic scripts -->

<!--[if !IE]> -->

<script src="/static/admin/js/jquery.min.js"></script>

<!-- <![endif]-->

{block name="myjs" }
<!--[if IE]>
<script src="/static/admin/js/1.10.2/jquery.min.js"></script>
<![endif]-->

<!--[if !IE]> -->

<script type="text/javascript">
    window.jQuery || document.write("<script src='/static/admin/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
    window.jQuery || document.write("<script src='/static/admin/js/jquery-1.10.2.min.js'>" + "<" + "/script>");
</script>
<![endif]-->

<script type="text/javascript">
    if ("ontouchend" in document) document.write("<script src='/static/admin/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script src="/static/admin/js/bootstrap.min.js"></script>
<script src="/static/admin/js/typeahead-bs2.min.js"></script>

<!-- page specific plugin scripts -->

<script src="/static/admin/js/jquery.dataTables.min.js"></script>
<script src="/static/admin/js/jquery.dataTables.bootstrap.js"></script>

<!-- ace scripts -->

<script src="/static/admin/js/ace-elements.min.js"></script>
<script src="/static/admin/js/ace.min.js"></script>

<!-- inline scripts related to this page -->

<script type="text/javascript">

    // 将非汉子和数字,字母,下划线替换成空
    ipp.oninput=function(){
        ipp.value = ipp.value.replace(/[^\w\u4E00-\u9FA5]/g, '');
    }

    toastr.options = {
        closeButton: true,// 是否显示关闭按钮
        progressBar: false,// 实现显示计时条
        timeOut: "3000",  // 自动关闭时间
//        positionClass: "toast-bottom-left" // 提示位置
         positionClass: "toast-top-full-width" // 提示位置
        // toast-top-full-width 顶端，宽度铺满整个屏幕
        // toast-top-right  顶端右边
    };

    $('.del-btn').click(function(){
        var rid=$(this).attr('data-oid');
        var pid=$(this).attr('data-pid');
        var tr=$(this).parents('tr');

        var td=$(this).parents('td');
        var tdd=td.prev();

        if(tdd.text()==7){
            alert('最低权限index--show不能删除');
        }else{
            if(confirm("确定要[删除]此角色的权限吗?"))
            {
                delAjax(rid,pid,tr);
            }
        }


    });

    function delAjax(rid,pid,tr){
        $.ajax({
            type:'delete',
            dataType:'json',
            url:'privilege/'+rid,
            data:{'pid':pid},
            success:function(data){
                console.log(data);
                if(data.status){
                    toastr.success('删除成功');
                    tr.remove();
                }else{
                    toastr.error('删除失败');
                }
            },
            error:function(){

            }
        });
    }



    $('.add-btn').click(function(){
            var name=$(this).attr('data-name');
            var id=$(this).attr('data-id');
        var option=$("option:contains('index--show')");
        console.log(option);
        option.attr("disabled",true);
            $('#rid').html('编号'+id);
            $('#rname').html('角色名'+name);
            $('#bianhao').val(id);
            $('#juese').val(name);
    })


    jQuery(function ($) {
        var oTable1 = $('#sample-table-2').dataTable({
            "aoColumns": [
                {"bSortable": false},
                null, null, null, null, null,
                {"bSortable": false}
            ]
        });


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


        $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
        function tooltip_placement(context, source) {
            var $source = $(source);
            var $parent = $source.closest('table')
            var off1 = $parent.offset();
            var w1 = $parent.width();

            var off2 = $source.offset();
            var w2 = $source.width();

            if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
            return 'left';
        }
    })

</script>
{/block}

<div style="display:none">
    <script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script>
</div>
</body>
</html>
